<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>时钟</title>
</head>
<body>
<div id="clock" style="font-size: 24px"></div>
<button id="start" value="开始">开始</button>
<button id="stop" value="停止">停止</button>
<script>
    let clock = document.getElementById("clock")
    let start = document.getElementById("start")
    let stop = document.getElementById("stop")

    callback();//???????
    let time = setInterval(callback,1000);
    function callback(){
        var date = new Date();
            clock.innerHTML = date.getHours() + ":"
                + date.getMinutes() + ":"
                + date.getSeconds();
    }
    start.onclick=function (){
        if(time==null){
            time=setInterval(callback,1000)
        }
    }
    stop.onclick=function (){
        clearInterval(time)
        time = null
    }
</script>
</body>
</html>
